package homework;

import java.io.File;
import java.util.Objects;
import java.util.Scanner;

/**
 * @classname:demo02
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/15 16:46
 * @version: 0.1
 * @since:1.8
 */
public class demo02 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入要遍历的目录");
        String dir = input.next();
        File directory = new File(dir);
        showDir(directory, "|-");
    }

    private static void showDir(File directory, String s) {
        Objects.requireNonNull(directory);
        if (!directory.exists()) {
            System.out.println("目录不存在");
            return;
        }
        File[] files = directory.listFiles();
        for (File file : files) {
            System.out.println(s + file.getName());
            if (file.isDirectory()) {
                showDir(file, "|" + s);
            }
        }
    }
}
